#自动取款机

#建一个用户表
userlist=[
            {'login':'zhangsan','passwd':'12345','balance':10000},
            {'login':'lisi','passwd':'23456','balance':50000},
            {'login':'wangwu','passwd':'34567','balance':80000}
          ]

#定义一个显示用户余额的函数
def showBalance(userlist):
    if len(userlist) == 0:
        print("============没有用户信息可以输出==============")
        return
    print("|{:5}|{:<10}|{:<8}".format("sid","login","balance"))
    print("-"*30)
    for i in range(len(userlist)):
        print("|{:5}|{:<10}|{:8}".format(i+1,userlist[i]['login'],userlist[i]['balance']))

while True:
    #初始界面
    print("="*8,"欢迎使用xx银行","="*8)
    print("{}{:>10}{:>8}".format(" ","1、登录","2、退出"))
    print("="*30)
    i = input("请选择：") 
    #次级界面
    if i == "1":
        for index in range(3):
            login = input("请输入您的用户名：")
            if login == userlist[index]['login']:
                print("用户存在！")
                #验证密码
                passwd = input("请输入您的密码：")
                if passwd == userlist[index]['passwd']:
                    print("输入正确！登陆成功")
                    input("按任意键继续...")
                    #用户属性
                    while True:
                        #操作界面
                        print("="*8,"xx银行","="*8)
                        print("{}{:<10}{:<10}".format(" ","1、查询余额","2、取钱"))
                        print("{}{:<12}{:<10}".format(" ","3、存钱","4、退出"))
                        j = input("请选择：")
                        #次级操作界面
                        if j == "1":
                            print("="*8,"账户余额查询","="*8)
                            showBalance(userlist)
                            input("按任意键继续")
                        elif j == "2":
                            #取款
                            print("="*8,"取款","="*8)
                            balance = int(input("请输入您的取款金额："))
                            print("取款成功")
                            print("共",balance,"元，请您收好")
                            userlist[index]['balance'] -= balance
                            showBalance(userlist)
                            input("按任意键继续")
                        elif j == "3":
                            #存款
                            print("="*8,"存款","="*8)
                            balance = int(input("请输入您的存入金额："))
                            print("存钱成功")
                            print("共存入",balance,"元，请您核对")
                            userlist[index]['balance'] += balance
                            showBalance(userlist)
                            input("按任意键继续")
                        elif j == "4":
                            print("="*8,"返回初始界面","="*8)
                            break
                        else:
                            print("========非常抱歉，我们没有该项服务...========")
                            print("========请您重新输入！========")
                else:
                    print("密码输入错误，请重新输入...")
            else:
                print("未找到该用户！")
    elif i == "2":
        print("="*8,"退出系统","="*8)
        break
    else:
        print("=======非常抱歉，我们没有该项服务...========")
        print("========请您重新输入！========")
